package com.basic.controller;

import com.basic.common.HttpResult;
import com.basic.contant.RabbitContant;
import com.basic.message.MessageContant;
import com.basic.service.TestService;
import com.basic.util.JedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("test")
public class TestController {

    /**
     * 对象池
     */

    @Autowired
    private TestService testService;

    final static Logger logger = LoggerFactory.getLogger(TestController.class);

    @GetMapping("/test1")
    public String test1() {

        return "hello word, 欢迎学习springboot零基础实战项目";
    }

    @PostMapping("/test/mysql")
    public String testMysql(@RequestParam("content") String content) {

        return "success : " + testService.addTestContent(content);
    }

    @GetMapping("/test/mysql/{id}")
    public String testMysqlQuery(@PathVariable("id") String id) {
        logger.info("查询test的content，通过id:{}", id);
        return testService.testMysqlQuery(id);
    }

    @GetMapping("/test")
    public String testMysqlQuery1(@RequestParam("id") String id) {

        return testService.testMysqlQuery(id);
    }

    @Autowired
    JedisUtil jedisUtil;

    @PostMapping("/send")
    public HttpResult sendMessage(@RequestParam("message") String message) {
        jedisUtil.lpush(MessageContant.ASYNC_LIST, message);
        return HttpResult.ok();
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test/mq")
    public HttpResult testMq() {
        rabbitTemplate.convertAndSend(RabbitContant.EXCHANGE_NAME, RabbitContant.ROUTING_KEY,"Hello word! 进入功能迭代");
        return HttpResult.ok();
    }




}
